<template>
  <div>
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align: center">
        <el-form-item label="问题">
          <el-input v-model="param.question" placeholder="请输入问题"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button size="small" type="primary" icon="el-icon-search" @click="loadCounsel">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-button size="small" type="primary" icon="el-icon-plus" @click="toAddHandle">新增</el-button>
    </div>

    <el-table size="small" :data="counsel">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      
      <el-table-column label="问题" prop="question" align="center" show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="提问时间" prop="questionTime" align="center"  width="112px"></el-table-column>
      <el-table-column label="回答" prop="replay" align="center"></el-table-column>
      <el-table-column label="回答时间" prop="replayTime" align="center"></el-table-column>
      <el-table-column label="状态" prop="status" align="center"></el-table-column>
      <el-table-column label="教授id" prop="professorId" align="center"></el-table-column>
      <el-table-column label="用户id" prop="userId" align="center"></el-table-column>
      <el-table-column label="操作" width="200px" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            :plain="true"
            icon="el-icon-edit"
            @click="edit(scope.row)"
          >回复</el-button>
          <el-button
            type="text"
            size="mini"
            :plain="true"
            style="color:green"
            icon="el-icon-refresh-right"
            @click="editHandler(scope.row)"
          >更改</el-button>
          <el-button
            type="text"
            size="mini"
            :plain="true"
            style="color:red"
            icon="el-icon-delete"
            @click="deleteHandler(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <el-dialog class="customer_modal" title="回复" :visible.sync="dialogVisible" width="60%">
       
        <el-form :model="param" label-width="100px">
            <el-form-item label="回复内容" >
                <el-input v-model="param.replay"></el-input>
            </el-form-item>

        </el-form>
       <span slot="footer" class="dialog-footer">
           <el-button @click="dialogVisible=false" size="small">取消</el-button>          
           <el-button type="primary" @click="save" size="small">确定</el-button>
       </span>
       </el-dialog>

   
    
    
   
  </div>
</template>

<script>
import { get, post, del } from "@/utils/request";
import getPageTitle from "../../utils/get-page-title";
export default {
  //页面数据
  data() {
    return {
      param: {},
      counsel: [],
      dialogVisible:false,
      timer: null,
    };
  },
  //页面渲染的时候会调用的函数
  created() {
    this.loadCounsel();
  },
  //所有的方法
  methods: {
    
    editHandler(row) {
      this.$router.push({
        path: "/BaseFile/Counsel_create",
        query: row
      });
    },
    loadCounsel() {
      let url = "http://121.196.106.124:8888/counsel/query";
      get(url, this.param).then(resp => {
        this.counsel = resp.data;
      });
    },
    toAddHandle() {
      this.$router.push("/BaseFile/Counsel_create");
    },
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        let url = "http://121.196.106.124:8888/counsel/deleteById";
        del(url, { id: row.id }).then(resp => {
          this.$message({ type: "success", message: resp.message });
          this.loadCounsel();
        });
      })
      .catch(_=>{});
    },
    created() {

      this.loadCounsel();
    },

    save(){
            let url = "http://121.196.106.124:8888/counsel/saveOrUpdate"   
            post(url,this.param).then((response)=>{
                this.dialogVisible=false;
                this.$message({type:"success",message:response.message})
                
            })

    
    },

            edit(row){
            this.param=row;
            this.dialogVisible=true;
        },

    
    /**subReplay(row){
      this.$confirm("是否确定回复",{
         confirmButtonText:"确定",
         cancelButtonText:"取消",
         type:"info" 
      }).then(()=>{
        let url = "http://121.196.106.124:8888/counsel/saveOrUpdate";
        post(url,{id:row.id}).then(resp=>{
          this.$message({type:"success",message:resp.message});
          this.loadCounsel();
          this.dialog = false;
        })
      })

    },**/
   
  }
};
</script>


<style scoped>
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}
</style>